home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / PartMaker 4.3 / WindowDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-12  |  10.6 KB  |  448 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        WindowDialog.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for application.            */
  28.  
  29. #ifndef __ERRORS__
  30. #include <Errors.h>
  31. #endif
  32.  
  33. #ifndef __UTILITIES__
  34. #include "Utilities.h"
  35. #endif
  36.  
  37.  
  38.  
  39. /*****************************************************************************/
  40.  
  41.  
  42.  
  43. extern RgnHandle    gCursorRgn;                /* We handle cursors here, so we need */
  44. extern CursPtr        gCursorPtr;                /* to know about these things. */
  45.                                             /* Above are DTS.Lib..framework globals. */
  46.  
  47. extern short        gDialogErr;                /* Error numbers to be displayed in   */
  48.                                             /* a dialog window of type 'ERR#' are */
  49.                                             /* passed in this way.                  */
  50.  
  51. static short    gCtlNum;
  52.  
  53.  
  54.  
  55. /*****************************************************************************/
  56. /*****************************************************************************/
  57.  
  58. #ifdef applec
  59. #pragma segment WindowDialog
  60. #endif
  61.  
  62. /*****************************************************************************/
  63. /*****************************************************************************/
  64.  
  65.  
  66.  
  67. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  68. /* See CalcFrameRgn() for info. */
  69.  
  70. void    DialogCalcFrameRgn(FileRecHndl frHndl, WindowPtr window, RgnHandle rgn)
  71. {
  72. #ifndef __MWERKS__
  73. #pragma unused (frHndl, window, rgn)
  74. #endif
  75. }
  76.  
  77.  
  78.  
  79. /*****************************************************************************/
  80.  
  81.  
  82.  
  83. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  84. /* See ContentClick() for info. */
  85.  
  86. void    DialogContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  87. {
  88. #ifndef __MWERKS__
  89. #pragma unused (firstClick)
  90. #endif
  91.  
  92.     FileRecHndl        ff;
  93.     short            oldRes;
  94.     short            cnum, action;
  95.     ControlHandle    ctl;
  96.  
  97.     ff = GetNextDocument(nil, 'PtMd');
  98.     PrepDocResFile(ff, &oldRes, fsRdPerm);
  99.  
  100.     gCtlNum = cnum = IsCtlEvent(window, event, &ctl, &action);
  101.     if ((cnum == -1) || (cnum == -2))
  102.         if (GetButtonVariant(ctl) == pushButProc)
  103.             DisposeOneWindow(window, kClose);
  104.  
  105.     return;
  106. }
  107.  
  108.  
  109.  
  110. /*****************************************************************************/
  111.  
  112.  
  113.  
  114. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  115. /* See ContentKey() for info. */
  116.  
  117. Boolean    DialogContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
  118. {
  119. #ifndef __MWERKS__
  120. #pragma unused (passThrough)
  121. #endif
  122.  
  123.     FileRecHndl        ff;
  124.     short            oldRes;
  125.     short            cnum, action;
  126.     ControlHandle    ctl;
  127.  
  128.     ff = GetNextDocument(nil, 'PtMd');
  129.     PrepDocResFile(ff, &oldRes, fsRdPerm);
  130.  
  131.     gCtlNum = cnum = IsCtlEvent(window, event, &ctl, &action);
  132.     if ((cnum == -1) || (cnum == -2)) {
  133.         if (GetButtonVariant(ctl) == pushButProc) {
  134.             DisposeOneWindow(window, kClose);
  135.             return(true);
  136.         }
  137.     }
  138.  
  139. #if DEV_VERSION
  140.     if ((event->message & charCodeMask) == (unsigned char)'≥') {
  141.         if ((event->modifiers & (optionKey | cmdKey)) == (optionKey | cmdKey)) {
  142.             gCtlNum = -2;
  143.             DisposeOneWindow(window, kClose);
  144.         }
  145.     }
  146. #endif
  147.  
  148.     return(true);
  149. }
  150.  
  151.  
  152.  
  153. /*****************************************************************************/
  154.  
  155.  
  156.  
  157. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  158. /* See DrawFrame() for info. */
  159.  
  160. void    DialogDrawFrame(FileRecHndl frHndl, WindowPtr window, Boolean activate)
  161. {
  162.     MoveTo(0, (*frHndl)->fileState.topSidebar - 1);
  163.     LineTo((*frHndl)->fileState.leftSidebar - 1 - 16384, (*frHndl)->fileState.topSidebar - 1);
  164.     LineTo((*frHndl)->fileState.leftSidebar - 1 - 16384, 16383);
  165.  
  166.     BeginFrame(window);
  167.     DoDrawControls(window, activate);
  168.     EndFrame(window);
  169. }
  170.  
  171.  
  172.  
  173. /*****************************************************************************/
  174.  
  175.  
  176.  
  177. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  178. /* See FreeDocument() for info. */
  179.  
  180. OSErr    DialogFreeDocument(FileRecHndl frHndl)
  181. {
  182.     return(DefaultFreeDocument(frHndl));
  183. }
  184.  
  185.  
  186.  
  187. /*****************************************************************************/
  188.  
  189.  
  190.  
  191. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  192. /* See FreeWindow() for info. */
  193.  
  194. OSErr    DialogFreeWindow(FileRecHndl frHndl, WindowPtr window)
  195. {
  196. #ifndef __MWERKS__
  197. #pragma unused (frHndl, window)
  198. #endif
  199.  
  200. /* For dialogs that need to keep their info before getting dismissed:
  201. **   Check gCtlNum to see what control caused dialog dismissal.
  202. **     -1: Default button.
  203. **     -2: Cancel button.
  204. **   If you determine that the dialog shouldn't be dismissed after all, then
  205. **   return an error.
  206. */
  207.  
  208.     return(noErr);
  209. }
  210.  
  211.  
  212.  
  213. /*****************************************************************************/
  214.  
  215.  
  216.  
  217. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  218. /* See ImageDocument() for info. */
  219.  
  220. OSErr    DialogImageDocument(FileRecHndl frHndl)
  221. {
  222. #ifndef __MWERKS__
  223. #pragma unused (frHndl)
  224. #endif
  225.  
  226.     FileRecHndl    ff;
  227.     short        oldRes;
  228.  
  229.     ff = GetNextDocument(nil, 'PtMd');
  230.     PrepDocResFile(ff, &oldRes, fsRdPerm);
  231.     DoDrawControls((*frHndl)->fileState.window, false);        /* Draw the content controls. */
  232. //    if (ff) CloseDocResFile(ff);
  233.  
  234.     return(noErr);
  235. }
  236.  
  237.  
  238.  
  239. /*****************************************************************************/
  240.  
  241.  
  242.  
  243. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  244. /* See InitContent() for info. */
  245.  
  246. OSErr    DialogInitContent(FileRecHndl frHndl, WindowPtr window)
  247. {
  248.     FileRecHndl        ff;
  249.     short            oldRes;
  250.     OSErr            err;
  251.     OSType            sftype;
  252.     ControlHandle    ctl;
  253.     Str255            pstr;
  254.  
  255.     ff = GetNextDocument(nil, 'PtMd');
  256.     PrepDocResFile(ff, &oldRes, fsRdPerm);
  257.  
  258.     sftype = (*frHndl)->fileState.sfType;
  259.     err = AddControlSet(window, sftype, kwStandardVis, 0, 0, nil);
  260.     if (sftype == 'ERR#') {
  261.         CNum2Ctl(window, 100, &ctl);
  262.         if (ctl) {
  263.             CTEGetPStr(ctl, pstr);
  264.             pcatdec(pstr, gDialogErr);
  265.             gDialogErr = noErr;
  266.             CTESetPStr(ctl, pstr);
  267.         }
  268.     }
  269.  
  270.     UseResFile(oldRes);
  271.     return(err);
  272. }
  273.  
  274.  
  275.  
  276. /*****************************************************************************/
  277.  
  278.  
  279.  
  280. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  281. /* See ResizeContent() for info. */
  282.  
  283. void    DialogResizeContent(WindowPtr window, short oldh, short oldv)
  284. {
  285. #ifndef __MWERKS__
  286. #pragma unused (window, oldh, oldv)
  287. #endif
  288. }
  289.  
  290.  
  291.  
  292. /*****************************************************************************/
  293.  
  294.  
  295.  
  296. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  297. /* See ScrollFrame() for info. */
  298.  
  299. void    DialogScrollFrame(FileRecHndl frHndl, WindowPtr window, long dh, long dv)
  300. {
  301. #ifndef __MWERKS__
  302. #pragma unused (frHndl, window, dh, dv)
  303. #endif
  304. }
  305.  
  306.  
  307.  
  308. /*****************************************************************************/
  309.  
  310.  
  311.  
  312. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  313. /* See UndoFixup() for info. */
  314.  
  315. void    DialogUndoFixup(FileRecHndl frHndl, Point contOrg, Boolean afterUndo)
  316. {
  317. #ifndef __MWERKS__
  318. #pragma unused (frHndl, contOrg, afterUndo)
  319. #endif
  320.  
  321.     /* See DTS.Draw for an example of what you might do here. */
  322. }
  323.  
  324.  
  325.  
  326. /*****************************************************************************/
  327.  
  328.  
  329.  
  330. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  331. /* See WindowCursor() for info. */
  332.  
  333. Boolean    DialogWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
  334. {
  335.     WindowPtr        oldPort;
  336.     RgnHandle        contRgn;
  337.     Rect            rr, teViewRct, contRct;
  338.     TEHandle        teHndl;
  339.     ControlHandle    viewCtl;
  340.     Point            contOrg;
  341.     CTEDataHndl        teData;
  342.     short            mode;
  343.  
  344.     if (!window) {
  345.         SetCursor(gCursorPtr = &qd.arrow);
  346.         return(true);
  347.     }
  348.  
  349.     oldPort = SetFilePort(frHndl);
  350.     window = (*frHndl)->fileState.window;
  351.  
  352.     GetContentOrigin(window, &contOrg);
  353.     SetOrigin(contOrg.h, contOrg.v);        /* Scroll position of window. */
  354.  
  355.     GetContentRect(window, &contRct);
  356.         /* This returns the content portion of the window in local coordinates,
  357.         ** less document scrollbar and sidebar areas. */
  358.  
  359.     contRgn = NewRgn();
  360.     for (viewCtl = nil; ((viewCtl = CTENext(window, &teHndl, viewCtl, 1, false)) != nil);) {
  361.         teViewRct = (*teHndl)->viewRect;
  362.         SectRect(&teViewRct, &contRct, &rr);
  363.         LocalToGlobalRect(&rr);
  364.         if ((*viewCtl)->contrlVis) {
  365.             if (!(*viewCtl)->contrlHilite) {
  366.                 if (!CTEReadOnly(teHndl)) {
  367.                     RectRgn(contRgn, &rr);
  368.                     teData = (CTEDataHndl)(*viewCtl)->contrlData;
  369.                     mode   = (*teData)->mode;
  370.                     if ((mode & cteActive) || (!(mode & cteTwoStep))) {
  371.                         if (PtInRect(globalPt, &rr)) {
  372.                             gCursorPtr = DoSetResCursor(iBeamCursor);
  373.                             SectRgn(gCursorRgn, contRgn, gCursorRgn);
  374.                             DisposeRgn(contRgn);
  375.                             SetPort(oldPort);
  376.                             return(true);
  377.                         }
  378.                     }
  379.                     DiffRgn(gCursorRgn, contRgn, gCursorRgn);
  380.                 }
  381.             }
  382.         }
  383.     }
  384.     SetCursor(gCursorPtr = &qd.arrow);
  385.     DisposeRgn(contRgn);
  386.     return(true);
  387. }
  388.  
  389.  
  390.  
  391. /*****************************************************************************/
  392.  
  393.  
  394.  
  395. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  396. /* See WindowGoneFixup() for info. */
  397.  
  398. void    DialogWindowGoneFixup(WindowPtr window)
  399. {
  400. #ifndef __MWERKS__
  401. #pragma unused (window)
  402. #endif
  403. }
  404.  
  405.  
  406.  
  407. /*****************************************************************************/
  408. /*****************************************************************************/
  409. /*****************************************************************************/
  410.  
  411.  
  412.  
  413. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  414. /* See AdjustMenuItems() for info. */
  415.  
  416. Boolean    DialogAdjustMenuItems(WindowPtr window, short menuID)
  417. {
  418. #ifndef __MWERKS__
  419. #pragma unused (window)
  420. #endif
  421.  
  422.     if (menuID == mEdit)
  423.         CTEEditMenu(nil, mEdit, UnmapMItem(mEdit, kStdUndo), UnmapMItem(mEdit, kStdCut));
  424.  
  425.     return(false);
  426. }
  427.  
  428.  
  429.  
  430. /*****************************************************************************/
  431.  
  432.  
  433.  
  434. /* •• You don't call this.  DTS.Lib..framework does for appropriate document type(s). •• */
  435. /* See DoMenuItem() for info. */
  436.  
  437. Boolean    DialogDoMenuItem(WindowPtr window, short menuID, short menuItem)
  438. {
  439. #ifndef __MWERKS__
  440. #pragma unused (window)
  441. #endif
  442.  
  443.     return(DoMenuCommand(menuID, menuItem));
  444. }
  445.  
  446.  
  447.  
  448.